Method for adjusting focus position and electronic apparatus

ABSTRACT

A method for adjusting focus position and an electronic apparatus are provided. Herein, a depth map is obtained according to a first image and a second image which are captured by a first lens and a second lens, respectively. A plurality of depth values included in the depth map is compared with a depth of field (DOF) table for obtaining a plurality of focus distances. An All-in-Focus (AIF) image is generated according to a plurality of focus images captured by the first lens with the focus distances, respectively. A blur process is executed for a plurality of pixels excluding a focus selected location in the AIF image, so as to obtain an adjusting image.

CROSS-REFERENCE TO RELATED APPLICATION

This application claims the priority benefit of Taiwan applicationserial no. 102122985, filed on Jun. 27, 2013. The entirety of theabove-mentioned patent application is hereby incorporated by referenceherein and made a part of this specification.

BACKGROUND OF THE INVENTION

1. Field of the Invention

This invention generally relates to an image processing method and anapparatus, and more particularly to a method for adjusting focusposition and an electronic apparatus using the same.

2. Description of Related Art

Accompanying with the advancement of the optical projection technology,cameras having adjustable aperture, shutter or even replaceable lensesare gradually popularized, and functionalities of the cameras also tendto more diversified. When a camera is used to capture an image, in orderto bring out a theme of the captured image, a capturing technique knownas shallow depth of field is generally adopted by focusing a lens of thecamera onto a specific distance range in the image, such that objectswithin the specific distance range can be clearly rendered whilegradually blurring other objects outside of the specific distance range.A so-called depth of field (DOF) is used to describe a distance rangefor clearly rendering the image in a space.

However, the shallow depth of field that can be generated by a normalcamera lens provides only limited effects, and in order to obtain a morepreferable shallow depth of field, a lens with an large aperture isrequired to enhance blur process to distant objects, so that the themethat is clearly rendered can be bring out from background. However, thelens with large aperture is usually huge in size and high in price,which cannot be easily provided to a general consumer camera.Accordingly, a technical problem to be solved in the field is togenerate an image with shallow depth of field by using a consumer cameraof lower level.

SUMMARY OF THE INVENTION

The invention is directed a method for adjusting focus position and anelectronic apparatus, in which an image post-process is utilized toadjust the focus position.

A method for adjusting focus position of the invention is suitable foran electronic apparatus. The method includes: obtaining a depth mapaccording to a first image and a second image which are respectivelycaptured by a first lens and a second lens; obtaining a plurality offocus distances by comparing a plurality of depth values included in thedepth map with a depth of field table; generating an all-in-focus imageaccording to a plurality of focus images captured by the first lensrespectively with the focus distances; and obtaining an adjusting imageby executing a blur process for a plurality of pixels excluding a focusselected location in the all-in-focus image.

In an embodiment of the invention, after the all-in-focus image isgenerated, the all-in-focus image is displayed, and the focus selectedlocation that is selected in the all-in-focus image by a user isreceived.

In an embodiment of the invention, in the step of obtaining theadjusting image by executing the blur process for the pixels excludingthe focus selected location in the all-in-focus image, a designateddepth value corresponding to the focus selected location is obtainedfrom the depth map, and the depth values corresponding to each of thepixels respectively is compared with the designated depth value toexecute the blur process for each of the pixels.

In an embodiment of the invention, in the step of comparing the depthvalues corresponding to the pixels respectively with the designateddepth value, a blur level corresponding to each of the pixels isadjusted according to a difference value between each of the depthvalues and the designated depth value, and the blur process is executedfor the pixels according to the blur level.

In an embodiment of the invention, after the step of generating theall-in-focus image according to the focus images, a blur strength valueis received, and a range of the blur level is decided according to theblur strength value.

In an embodiment of the invention, in the step of obtaining the depthmap according to the first image and the second image which arerespectively captured by the first lens and the second lens, the firstimage and the second image are simultaneously captured by the first lensand the second lens respectively with a base focus; a horizontal shiftvalue of the first image and the second image is calculated; and thedepth map is obtained by using the first image as a reference accordingto a lens distance between the first lens and the second lens, the basefocus and the horizontal shift value.

In an embodiment of the invention, the depth of field table is built inthe electronic apparatus.

An electronic of the invention includes an image capturing unit, astorage unit and a processing unit. The image capturing unit includes afirst lens and a second lens. The storage unit stores images captured bythe image capturing unit. The processing unit is coupled to the imagecapturing unit and the storage unit, and configured to execute an imageprocessing module. The image processing module includes: a depth mapcapturing module that obtains a depth map according to a first image anda second image which are respectively captured by a first lens and asecond lens; a comparing module that obtains a plurality of focusdistances by comparing a plurality of depth values included in the depthmap with a depth of field table; an all-in-focus generation module thatgenerates an all-in-focus image according to a plurality of focus imagescaptured by the first lens respectively with the focus distances; and afocus adjusting module that obtains an adjusting image by executing ablur process for a plurality of pixels excluding a focus selectedlocation in the all-in-focus image.

In an embodiment of the invention, the electronic apparatus furtherincludes: a display module that displays the all-in-focus image; and aninput module that receives the focus selected location which is selectedin the all-in-focus image by a user.

In an embodiment of the invention, the input module receives a blurstrength value, and the focus adjusting module decides a range of a blurlevel according to the blur strength value.

In an embodiment of the invention, the focus adjusting module obtains adesignated depth value corresponding to the focus selected location fromthe depth map, compares the depth values corresponding to each of thepixels respectively with the designated depth value for obtaining adifference value between each of the depth values and the designateddepth value, adjusts the blur level corresponding to each of the pixelsaccording to the difference value, and executes the blur process foreach of the pixels according to the blur level.

In an embodiment of the invention, the first image and the second imageare simultaneously captured by the first lens and the second lensrespectively with a base focus. The depth map capturing modulecalculates a horizontal shift value of the first image and the secondimage, and obtains the depth map by using the first image as a referenceaccording to a lens distance between the first lens and the second lens,the base focus and the horizontal shift value.

In summary, the invention obtains the all-in-focus image by utilizing animage post process, and adjusts the focus position in the all-in-focusimage, so that the captured image can provide an effect of shallow depthof field. Accordingly, the method of the invention may be utilized forobtaining the same effect of shallow depth, even for those electronicapparatuses without high level equipments such as the large aperture.

To make the above features and advantages of the disclosure morecomprehensible, several embodiments accompanied with drawings aredescribed in detail as follows.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of an electronic apparatus according to anembodiment of the invention.

FIG. 2 is a flowchart of a method for adjusting focus position accordingto an embodiment of the invention.

FIG. 3 is a schematic diagram for calculating a depth value according toan embodiment of the invention.

FIG. 4 is a block diagram of an electronic apparatus according toanother embodiment of the invention.

FIG. 5 is a schematic diagram for displaying an all-in-focus imageaccording to an embodiment of the invention.

FIG. 6 is a schematic diagram illustrating an adjusting image accordingto an embodiment of the invention.

DESCRIPTION OF THE EMBODIMENTS

The invention proposes a method for adjusting focus position and anelectronic apparatus, in which after an image is captured, an adjustingimage being refocused can be generated according to a focus selectedlocation by utilizing an image post process. In order to make theinvention more comprehensible, embodiments are described below as theexamples to prove that the invention can actually be realized.

FIG. 1 is a block diagram of an electronic apparatus according to anembodiment of the invention. Referring to FIG. 1, an electronicapparatus 10 of the present embodiment is, for example, a mobile phone,a smart phone, a personal digital assistant (PDA), a PDA phone, anotebook computer or tablet computer, and including an image capturingunit 110, a processing unit 120 and a storage unit 130.

The image capturing unit 110 includes a first lens 111 and a second lens112 which are configured to capture images. The first lens 111 and thesecond lens 112 are, for example, a standard lens, a wide-angle lens ora zoom lens. Among the first lens 111 and the second lens 112, one beinga left lens (configured to capture a left-eye image), whereas anotherone being a right lens (configured to capture a right-eye image).Moreover, the image capturing unit 110 may also include a photosensitiveelement or a diaphragm, but the invention is not limited thereto. Thephotosensitive element is, for example, a charge coupled device (CCD), acomplementary metal-oxide semiconductor (CMOS) device or other devices.It is emphasized that above-mentioned examples are not intended to limitthe invention.

The storage unit 130 is, for example, a fixed or a movable device in anypossible forms including a random access memory (RAM), a read-onlymemory (ROM), a flash memory, a hard drive or other similar devices, ora combination of the above-mentioned devices. In the present embodiment,the storage unit 130 is recorded with an image processing module 140capable of being executed by the processing unit 120.

The processing unit 120 is, for example, a central processing unit (CPU)or other programmable devices for general purpose or special purposesuch as a microprocessor and a digital signal processor (DSP), aprogrammable controller, an application specific integrated circuit(ASIC), a programmable logic device (PLD) or other similar devices or acombination of above-mentioned devices. The processing unit 120 iscoupled to the image capturing unit 110 and the storage unit 130, andconfigured to access and execute the image processing module 140recorded in the storage unit 130, so as to execute a function ofadjusting focus position.

The image processing module 140 is, for example, a program code segmentwritten by a computer programming language, and the program code segmentis stored in the storage unit 130, included with a plurality ofcommands, and executed by the processing unit 120. Moreover, in otherembodiments, the image processing module 140 can also be a hardwarecomponent composed by one or more circuits, and the hardware componentis coupled to the processing unit 120 and driven by the processing unit120, but the invention is not limited thereto. Herein, the imageprocessing module 140 includes a depth map capturing module 141, acomparing module 142, an all-in-focus image generation module 143 and afocus adjusting module 144. Detailed steps of adjusting focus positionexecuted by the electronic apparatus 10 are as described in thefollowing embodiment.

FIG. 2 is a flowchart of a method for adjusting focus position accordingto an embodiment of the invention. A method of the present embodiment issuitable for the electronic apparatus 10 depicted in FIG. 1. Thefollowing detailed steps are elaborated to describe the method foradjusting focus position of the present embodiment with the reference toeach element of the electronic apparatus 10.

First, in step S205, the depth map capturing module 141 obtains a depthmap according to a first image and a second image which are respectivelycaptured by the first lens 111 and the second lens 112. The depth map isconfigured to record one or more depth values from a base line of thefirst lens 111 and the second lens 112 to one or more objects to beobserved. Herein, the first image is used as a reference, and the depthvalue of each pixel in the first image is calculated.

More specifically, the first image and the second image aresimultaneously captured by the first lens 111 and the second lens 112respectively with an identical parameter. The parameter may include abase focus, an aperture, a shutter, a white balance, but the inventionis not limited thereto. Subsequently, the depth map capturing module 141calculates a horizontal shift value of the first image and the secondimage. Therein, for the object that is closer to the first lens 111 andthe second lens 112, the horizontal shift value of the first image andthe second image is getting greater, whereas for the object that isfarther from the first lens 111 and the second lens 112, the horizontalshift value of the first image and the second image is getting smaller.Next, using the first image as the reference, the depth map capturingmodule 141 obtains the depth map according to a lens distance betweenthe first lens 111 and the second lens 112, the base focus and thehorizontal shift value.

For instance, FIG. 3 is a schematic diagram for calculating a depthvalue according to an embodiment of the invention. In FIG. 3, a lineconnecting the first lens 111 with the second lens 112 is generallyknown as a base line 301. Since the first lens 111 shifts in ahorizontal direction away from the second lens 112, there is ahorizontal shift value d (disparity) in the horizontal direction betweenan object 31 in the first image and the object 31 in the second image.In the present embodiment, it is assumed that the base focus of thefirst lens 111 and the second lens 112 is f, and the lens distancebetween the first lens 111 and the second lens 112 is b, so that a depthvalue Z can be calculated with a formula of Z=(b×f)/d, and the depth mapis thereby obtained.

Subsequently, in step S210, the comparing module 142 obtains a pluralityof focus distances by comparing a plurality of depth values included inthe depth map with a depth of field table. Herein, the depth of fieldtable records a plurality of focus distances as well as a depth of fieldcorresponding to each of the focus distances. It can be known from thedepth map and the depth of field table that, how many captured images ofa scene are required to include all depth of fields of the scene, andthe focus distances for the captured images can also be decidedaccordingly. The depth of field table is as shown in Table 1, in whichone focus distance has one corresponding depth of field. The depth offield table of Table 1 is merely an example; it is not limited inpractical uses.

TABLE 1 Focus distance Depth of field 50 cm 40 cm to 60 cm 75 cm 60 cmto 80 cm 105 cm  80 cm to 110 cm

Thereafter, in step S215, the all-in-focus generation module 143generates an all-in-focus image according a plurality of focus imagescaptured by the first lens 111 (due to the depth map being calculatedbased on the first image) with above-mentioned focus distances. Theall-in-focus image is a photo that is all clear from foreground tobackground. For instance, N focal distances F_(—)1 to F_N are obtainedin step S210, that is, the depth of fields of the focal distances F_(—)1to F_N include all of the depth values recorded in the depth map.Subsequently, by using the first lens 111, a focus image I_(—)1 iscaptured with the focus distance F_(—)1, a focus image I_(—)2 iscaptured with the focus distance F_(—)2, . . . , and a focus image I_Nis captured with the focus distance F_N. Thereafter, the all-in-focusgeneration module 143 generates the all-in-focus image including all ofthe depth of fields of the scene, from the focus images I_(—)1 to I_Nwith an all-in-focus algorithm.

Thereafter, in step S220, the focus adjusting module 144 obtains anadjusting image by executing a blur process for a plurality of pixelsexcluding a focus selected location in the all-in-focus image. In otherwords, the all-in-focus image is refocused so that the focus position ischanged. For instance, after the all-in-focus image is generated, theelectronic apparatus 10 displays the all-in-focus image, and receivesthe focus selected location that is selected in the all-in-focus imageby a user, and then the blur process is executed for the pixelsexcluding the focus selected location in the all-in-focus image. Anotherembodiment is given for illustration below.

FIG. 4 is a block diagram of an electronic apparatus according toanother embodiment of the invention. Other members in the electronicapparatus 10 are further described in the present embodiment. Referringto FIG. 4, the storage unit 130 further includes a depth of field table401 and an image database 402. That is, the depth of field table 401 isbuilt in the electronic apparatus 10. The image database 402 isconfigured to store the images captured by the image capturing unit 110.In addition, the electronic apparatus 10 further includes a displaymodule 411 and an input module 412. The display module 411 is, forexample, a display configured to display the all-in-focus image. Theinput module 412 is, for example, a button, a touch panel or amicrophone, configured for the user to select a focus selected locationin the all-in-focus image.

In addition, the display module 411 and the input module 412 can beintegrated into a touch screen in which the all-in-focus image isdisplayed, and the user can select the focus selected location on thetouch screen for refocusing. An embodiment is given for illustrationbelow.

FIG. 5 is a schematic diagram for displaying an all-in-focus imageaccording to an embodiment of the invention. Referring to FIG. 5, anall-in-focus image 510 is displayed in a touch screen 50, and the methodfor obtaining the all-in-focus image can refer to the description forsteps S205 to S215. Accordingly, the user is capable of selecting alocation on the touch screen 50 for refocusing. Moreover, in the presentembodiment, while the touch screen 50 is displaying the all-in-focusimage 510, a strength controlling function bar 520 can also bedisplayed, so that the user may select a blur strength value ofbackground at the same time, and a range of a blur level for thebackground can be decided according to the blur strength value. Thestrength controlling function bar 520 is configured to, for example,simulate changes in aperture size.

As shown in FIG. 5, the user clicks on a focus selected location 501 bya finger 530, so as to select a tire in forefront for refocusing. Afterthe focus selected location 501 is received by the input module 411, thefocus adjusting module 144 obtains the depth value corresponding to thefocus selected location 501 (i.e, a designated depth value D_preserve)from the depth map. Subsequently, the depth value corresponding to eachof the pixels is compared respectively with the designated depth value,so that a difference value between each of the depth values and thedesignated depth value is obtained, and then the blur levelcorresponding to each of the pixels is adjusted according to thedifference value. Lastly, the focus adjusting module 144 executes theblur process for each of the pixels according to the blur level. Theblur process can be, for example, a Gaussian filter blur algorithm or abilateral filter blur algorithm.

For instance, the blur process is not executed on the pixels with thedepth value that is identical to the designated depth value D_preserve,whereas for the pixels with the depth value that is not identical to thedesignated depth value D_preserve, the blur process can be decidedaccording to the difference value between the depth value and thedesignated depth value D_preserve. For instance, the blue levelcorresponding to each of the pixels can be adjusted according to thedifference value between each of the depth value and the designateddepth value, and the blur process is executed on each of the pixelaccording to the blur level. The difference value being greaterindicates that an actual position corresponding to the pixel is fartheraway from a focal plane, thus the blur level is greater. Otherwise, thedifference value being smaller indicates that the actual positioncorresponding to the pixel is closer to the focal plane, thus the blurlevel is smaller.

With the blur strength value selected according to the focus selectedlocation 501 and the strength controlling function bar 520, an adjustingimage 600 depicted in FIG. 6 can be obtained. FIG. 6 is a schematicdiagram illustrating an adjusting image according to an embodiment ofthe invention. In FIG. 6, for the convenience of the description, theforeground, being an area (where the tire at forefront is) having thesame depth value with the focus selected location 501, is onlyillustrated in full line, and the background is only illustrated indotted line, and the blur level is not exhibited in FIG. 6. However, itcan be realized that, in an actual image presentation, the backgroundhas different blur levels according to the difference values. Inaddition, after the adjusting image 600 is displayed, the blur strengthvalue thereof can still be adjusted through the strength controllingfunction bar 520.

In summary, in the foregoing embodiments, two lenses are utilized toobtain the left-image and the right-image, so that the depth map can bethereby obtained. The all-in-focus image can be generated according tothe depth map. The adjusting image being refocused can then be generatedaccording to the all-in-focus image. Accordingly, the image post processcan be utilized for the user to selected the focus position forrefocusing, and adjust the blur strength value excluding the area otherthan the focus selected location, so that the adjusting image mayobtained an effect of large aperture.

It will be apparent to those skilled in the art that variousmodifications and variations can be made to the structure of the presentdisclosure without departing from the scope or spirit of the disclosure.In view of the foregoing, it is intended that the present disclosurecover modifications and variations of this disclosure provided they fallwithin the scope of the following claims and their equivalents.

What is claimed is:
 1. A method for adjusting focus position, for anelectronic apparatus, the method comprising: obtaining a depth mapaccording to a first image and a second image which are respectivelycaptured by a first lens and a second lens; obtaining a plurality offocus distances by comparing a plurality of depth values included in thedepth map with a depth of field table; generating an all-in-focus imageaccording to a plurality of focus images captured by the first lensrespectively with the focus distances; and obtaining an adjusting imageby executing a blur process for a plurality of pixels excluding a focusselected location in the all-in-focus image.
 2. The method of claim 1,wherein after the step of generating the all-in-focus image, furthercomprising: displaying the all-in-focus image, and receiving the focusselected location that is selected in the all-in-focus image by a user.3. The method of claim 1, wherein the step of obtaining the adjustingimage by executing the blur process for the pixels excluding the focusselected location in the all-in-focus image comprises: obtaining adesignated depth value corresponding to the focus selected location fromthe depth map; and comparing the depth values corresponding to thepixels respectively with the designated depth value to execute the blurprocess for the pixels.
 4. The method of claim 3, wherein the step ofcomparing the depth values corresponding to the pixels respectively withthe designated depth value comprises: adjusting a blur levelcorresponding to each of the pixels according to a difference valuebetween each of the depth values and the designated depth value; andexecuting the blur process for each of the pixels according to the blurlevel.
 5. The method of claim 4, wherein after the step of generatingthe all-in-focus image according to the focus images, furthercomprising: receiving a blur strength value; and deciding a range of theblur level according to the blur strength value.
 6. The method of claim1, wherein the step of obtaining the depth map according to the firstimage and the second image which are respectively captured by the firstlens and the second lens comprises: simultaneously capturing the firstimage and the second image by the first lens and the second lensrespectively with a base focus; calculating a horizontal shift value ofthe first image and the second image; and obtaining the depth map byusing the first image as a reference according to a lens distancebetween the first lens and the second lens, the base focus and thehorizontal shift value.
 7. The method claim 1, wherein depth of fieldtable is built in the electronic apparatus.
 8. An electronic apparatus,comprising: an image capturing unit including a first lens and a secondlens; a storage unit storing images captured by the image capturingunit; and a processing unit coupled to the image capturing unit and thestorage unit, and configured to execute an image processing module,wherein the image processing module comprises: a depth map capturingmodule obtaining a depth map according to a first image and a secondimage which are respectively captured by a first lens and a second lens;a comparing module obtaining a plurality of focus distances by comparinga plurality of depth values included in the depth map with a depth offield table; an all-in-focus generation module generating anall-in-focus image according to a plurality of focus images captured bythe first lens respectively with the focus distances; and a focusadjusting module obtaining an adjusting image by executing a blurprocess for a plurality of pixels excluding a focus selected location inthe all-in-focus image.
 9. The electronic apparatus of claim 8, whereinthe electronic apparatus further comprises: a display module displayingthe all-in-focus image; and an input module receiving the focus selectedlocation which is selected in the all-in-focus image by a user.
 10. Theelectronic apparatus of claim 9, wherein the input module receives ablur strength value, and the focus adjusting module decides a range of ablur level according to the blur strength value.
 11. The electronicapparatus of claim 10, wherein the focus adjusting module obtains adesignated depth value corresponding to the focus selected location fromthe depth map, compares the depth values corresponding to the pixelsrespectively with the designated depth value for obtaining a differencevalue between each of the depth values and the designated depth value,adjusts the blur level corresponding to each of the pixels according tothe difference value, and executes the blur process for each of thepixels according to the blur level.
 12. The electronic apparatus ofclaim 8, wherein the first image and the second image are simultaneouslycaptured by the first lens and the second lens respectively with a basefocus; wherein the depth map capturing module calculates a horizontalshift value of the first image and the second image, and obtains thedepth map by using the first image as a reference according to a lensdistance between the first lens and the second lens, the base focus andthe horizontal shift value.